<template>
	<view class="cardetails">
		<u-navbar back-icon-color="#FFFFFF" :back-text-style="backText" title-color="#FFFFFF" :background="barbg" back-text="返回"
		 title="车辆详情">
			<view class="navbar-right" slot="right" @tap="gotoEdit">编辑</view>
		</u-navbar>
		<!-- 司机信息 -->
		<view class="carmessage div">
			<view class="img">
				<!-- <image src="../../../../static/car.jpg" mode=""></image> -->
				<image class="img-header" :src="cardata.logo" mode="scaleToFill" lazy-load="true" v-if="cardata.logo"></image>
				<!-- <image class="img-header" src="../../../../static/car.jpg" mode="scaleToFill" lazy-load="true" v-else></image> -->
			</view>
			<view class="cartext">
				<u-row :gutter="0">
					<u-col :span="3">车牌：</u-col>
					<u-col :span="9">{{cardata.carNumber}}</u-col>
				</u-row>
				<u-row :gutter="0">
					<u-col :span="3">司机：</u-col>
					<u-col :span="9">{{cardata.driverName}}</u-col>
				</u-row :gutter="0">
				<u-row :gutter="0">
					<u-col :span="3">电话：</u-col>
					<u-col :span="9">{{cardata.driverPhone}}</u-col>
				</u-row>
				<u-row :gutter="0">
					<u-col :span="3">车队：</u-col>
					<u-col :span="9">{{cardata.teamName}}</u-col>
				</u-row>
			</view>
		</view>

		<!-- 消息box -->
		<view class="messagebox div">
			<view class="item">
				<view class="number red">{{reportData.cost}}</view>
				<view class="text">总费用(元)</view>
			</view>
<!-- 			<view class="item">
				<view class="number">{{datalist.thismoney}}</view>
				<view class="text">本月费用</view>
			</view> -->
			<view class="item">
				<view class="number">{{reportData.count}}</view>
				<view class="text">总运输次数</view>
			</view>
<!-- 			<view class="item">
				<view class="number">{{datalist.carnum}}</view>
				<view class="text">车辆数量</view>
			</view> -->
		</view>

		<!-- 跳转 -->
		<view class="goturl div">
			<view class="datawatch" @tap="goto(1)">
				<view class="left">
					<image src="../../../../static/shujubaobiao.png" mode="" style="vertical-align:middle;margin-right: 20rpx;"></image>
					<text>数据报表</text>
				</view>
				<view class="right">
					<!-- <image src="../../../../static/right.png" mode=""></image> -->
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="datawatch" @tap="goto(0)">
				<view class="left">
					<image src="../../../../static/shujubaobiao.png" mode="" style="vertical-align:middle;margin-right: 20rpx;"></image>
					<text>运行记录</text>
				</view>
				<view class="right">
					<!-- <image src="../../../../static/right.png" mode=""></image> -->
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
		</view>

<!-- 		dialog 弹出编辑框
		<u-popup v-model="dialogShow" mode="center" height="900rpx" width="85%" :closeable="true" border-radius="13" style="z-index: 0;">
			<view class="form">
				昨夜星辰昨夜风，画楼西畔桂堂东
			</view>
		</u-popup> -->
	</view>
</template>

<script>
	import {
		readCar
	} from "@/api/car.js"
	import {
		getReportData
	} from "@/api/dataReport.js"
	export default {
		data() {
			return {
				barbg: {
					background: '#5c92ff'
				},
				backText: {
					color: '#FFFFFF'
				},
				// datalist: {
				// 	allmoney: 40240,
				// 	thismoney: 2500,
				// 	allnum: 237,
				// 	carnum: 17
				// },
				dialogShow: false,
				cardata: {},
				carID: null,
				queryData: {
					action: 'count',
					group: 'carId',
					carId: null
				},
				reportData: {}
			}
		},
		created() {
			this.getCar()
			this.getCarData()
		},
		onLoad({id}) {
			this.carID = this.queryData.carId = id
			// console.log(this.carID)
		},
		methods: {
			gotoEdit(){
				// console.log(this.cardata)
				let {
					carNumber,
					type,
					driverName,
					driverPhone,
					id,
					iotId
				} = this.cardata
				let data = {
					carNumber,
					type,
					driverName,
					driverPhone,
					id,
					iotId
				}
				this.$urlTo.togo("./editCar/editCar" , data)
			},
			getCar() {
				readCar(this.carID).then(res => {
					if (res.code !== 1) {
						uni.showToast({
							title: res.msg,
							icon: "none",
							duration: 2000
						})
						return
					}
					console.log(res);
					this.cardata = res.result
					this.cardata.teamName = uni.getStorageSync('teamName')
					// this.$forceUpdate()
				})
			},
			getCarData(){
				getReportData(this.queryData).then(res =>{
					// console.log(res);
					this.reportData = res.result[0]
				})
			},
			goto(status) {
				if (status) {
					uni.navigateTo({
						url: "../../../dataReport/carData/index"
					})
				} else {
					uni.navigateTo({
						url: "../carMap/carMap?id="+this.carID
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.navbar-right {
		padding: 0px 40rpx;
		color: #ffffff;
	}

	.cardetails {
		padding: 30rpx;

		.div {
			background-color: white;
			border-radius: 15rpx;
		}

		.messagebox {
			display: flex;
			justify-content: space-around;
			align-items: center;
			height: 150rpx;
			margin-bottom: 50rpx;

			.item {
				width: 25%;
				height: 80%;
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				align-items: center;
				border-right: 1px solid #cc;

				.number {
					font-size: 30rpx;
					font-weight: 550;
				}

				.red {
					color: red;
				}

				.text {
					color: #909090;
					font-size: 25rpx;
				}
			}

		}

		.goturl {
			margin-top: 50rpx;
			margin-bottom: 50rpx;

			.datawatch {
				border-bottom: 1rpx solid #f1f1f1;
				height: 100rpx;
				display: flex;
				justify-content: space-around;
				align-items: center;
				padding: 0 15rpx;

				&:active {
					background-color: #e2e2e2;
				}

				.left {
					width: 50%;
				}

				.right {
					width: 50%;
					text-align: right;
				}

				image {
					width: 39rpx;
					height: 29rpx;
				}
			}

		}

		.carmessage {
			padding: 30rpx;
			margin-bottom: 50rpx;

			.img {
				margin-bottom: 30rpx;

				image {
					width: 100%;
				}
			}

			.cartext {
				.u-row {
					height: 90rpx;
					border-bottom: 1px solid #eeeeee;
					
					.u-col:last-child {
						text-align: right !important;
						border-bottom: none;
						font-size: 30rpx;
						font-weight: 550;
					}

					.u-col:nth-child(1) {
						color: #b6b6b6;
						font-size: 30rpx;
						font-weight: 550;
					}

				}
			}
		}
	}
	.form{
		height: 100%;
		padding: 0 30rpx;
		padding-top: 100rpx;
	}
</style>
